var arr = new Array("iPhone 6S", "Mac", "10k", "UAS双飞7日游", "米兰订制婚纱", "最新LV限量版包包"),
	timer = null,
	flag = 0;
window.onload = function() {
	var title = document.getElementById("title"),
		play = document.getElementById("play"),
		stop = document.getElementById("stop");
	//鼠标事件
	play.onclick = playGame;
	stop.onclick = stopGame;
	//键盘事件
	document.onkeyup = function(event) {
		event = event || window.event;
		//回车键的键盘码是13
		if (event.keyCode == 13) {
			if (flag == 0) {
				console.log("play");
				playGame();
				flag = 1;
			} else {
				console.log("stop");
				stopGame();
				flag = 0;
			}
		}
	}
}

function playGame() {

	var title = document.getElementById("title");
	/*清除原來的定時器， 防止开多个定时器（ 鼠标点一次， 开一次）,使抽奖越来越快，停不下来*/
	clearInterval(timer);
	timer = setInterval(function() {
		var random = Math.floor(Math.random() * arr.length);
		title.innerHTML = arr[random];
	}, 100);
	var play=document.getElementById("play");
	play.style.background = "#999";
}

function stopGame() {
	clearInterval(timer);
	var play = document.getElementById("play");
	play.style.background = "#00fcfc";
}